import { _decorator, assetManager, Button, color, Component, Director, director, EventTouch, find, instantiate, Label, log, math, Node, Sprite, Tween, tween, UIOpacity, UITransform, v3 } from 'cc';
import { tongyongTS } from './tongyongTS';
import { weixinapi } from './weixinAIP';
import { SJTS } from '../../../jinruchangjing/SJTS';
import { CZdingshiqiTS } from './CZdingshiqiTS';
import TaskView from 'db://assets/3rd/Guyu/Scripts/[业务]/广告任务/View/TaskView';
import TaskResMgr from 'db://assets/3rd/Guyu/Scripts/[业务]/广告任务/Model/TaskResMgr';
import { UIManager } from 'db://assets/3rd/Guyu/Scripts/[框架]/通用UI/UIManager';
import TaskWeb from 'db://assets/3rd/Guyu/Scripts/[业务]/广告任务/Controller/TaskWeb';
import TaskProxy from 'db://assets/3rd/Guyu/Scripts/[业务]/广告任务/Controller/TaskProxy';
import { CommonUI } from '../../../3rd/Guyu/Scripts/[框架]/通用UI/CommonUI';



const { ccclass, property } = _decorator;

@ccclass('TSkaishichangjing')
export class TSkaishichangjing extends Component {

    // 在组件属性面板拖拽赋值
    @property(Node)
    startGame: Node = null;

    ty: tongyongTS

    readonly f分享加道具数 = 2
    readonly m每日进入体力补充数 = 5

    HC_qiandao_riqi = -1
    HC_wuxian_riqi = -1

    HC_tilizhi = 5

    HC_qian = 200
    HC_XLMJ_zuigaofen = 0
    HC_ZGguang = 0

    HC_MLGM_chuangguangshu = 0

    HC_doudongshu = 3
    HC_wuxiantili = false



    HC_JS_MLGM = false          //麻了个嘛        
    HC_JS_MJXGQ = false             //麻将消个球
    HC_JS_JYMJ = false           //解压麻将
    HC_JS_XLMJ = false       //下落麻将

    wudianMode  = 0 ;



    protected async onEnable(): Promise<void> {
        await TaskResMgr.init();
        this.分析用户是否来源是买量平台()
    }

    protected onDestroy(): void {
        TaskResMgr.destroy();
    }

    private 分析用户是否来源是买量平台(): void {
        // const AD_SCENES = [
        //     1045,
        //     1046,
        //     1067,
        //     1068,
        //     1084,
        //     1095,
        //     1189,
        //     1200,
        //     1201,
        //     1215,
        //     1128,
        //     1230,
        //     1232,
        //     1238,
        //     1274,
        //     1295
        // ];
        // if (AD_SCENES.indexOf(wx_scene) != -1) {
        //     is_from_wxad = true;
        // }  此部分暂时隐藏，防止微信人员通过模拟环境进入发现

        //   获取到微信小游戏启动参数
        let launchOptions = wx.getLaunchOptionsSync()
        Guyu.Log.debug('++++小游戏启动参数++++', launchOptions);
        let query = launchOptions.query

        let is_from_wxad = false; // 用户来源是增长用户广告

        let is_from_wxad_roi = false;  // 用户来源是ROI买量


        // 来源一包多发腾讯渠道
        if (query.wxgamepro == 'PkgCBgAAoXkpQY9468Dae1E2') {
            Guyu.Log.debug('当前用户来源腾讯渠道买量参数：', query.wxgamepro);
            is_from_wxad = true;
        }

        // 来源一包多发腾讯ROI渠道
        if (query.wxgamepro == 'PkgCBgAAoXkpQY9468Dae1Ez') {
            Guyu.Log.debug('当前用户来源腾讯渠道买量参数：', query.wxgamepro);
            is_from_wxad_roi = true;
        }

        let config = TaskProxy.inst.taskConfig;
        // 如果来源是用户增长广告
        if (is_from_wxad) {
            // 判断是否开启误触
            if (config.is_wudian_ys == 1) {
                this.wudianMode = 1;
                this.fucWudianYs()
            } else {
                this.showOtherAd()
            }
            this.showInsetAd(true)


            // 如果是先弹出插屏,后弹出激励
            if (config.force_click_mode == 2) {
                this.solveReward()
            }
        }

        if (is_from_wxad_roi) {

            // 判断是否开启误触
            if (config.roi_is_wudian_ys == 1) {
                this.wudianMode = 2;
                this.fucWudianYs()
            } else {
                this.showRoiOtherAd()
            }
            this.showInsetAd(true)


            // 如果是先弹出插屏,后弹出激励
            if (config.force_click_mode == 2) {
                this.solveReward()
            }

        }

        if (!is_from_wxad && !is_from_wxad_roi) {
            // 展示原生广告
            this.showCustomAd()
            // 展示插屏广告
            this.scheduleOnce(() => {
                this.showInsetAd(false)
            }, config.insetad_play_time);
        }


        // 2025年06-16第一次上传的逻辑
        // // 如果广告来源是买量
        // if (is_from_wxad) {
        //     // 说明当前需要进入以后强制播放激励广告
        //     if (config.is_force_show_reward) {
        //         this.showForceRewardAd()
        //     } else {
        //         this.showOtherAd()
        //     }

        //     this.showOtherAd()

        // } else {
        //     // 展示原生广告
        //     this.showCustomAd()
        //     // 展示插屏广告
        //     this.scheduleOnce(() => {
        //         this.showInsetAd(false)
        //     }, config.insetad_play_time);
        // }

    }

    fucWudianYs() {
        let config = TaskProxy.inst.taskConfig;

        Guyu.Log.debug('++++节点参数++++', this.startGame);

        this.startGame.setPosition(
            this.startGame.position.x,
            this.startGame.position.y - 200
        );
        Guyu.Log.debug('++++节点参数++++', this.startGame.position);

        this.wudianCircleYs()

        // 展示格子广告
        if (config.is_show_gezi) {
            this.showGeziAd()
        }
    }

    // 循环展示隐藏原生广告
    wudianCircleYs() {

        let config = TaskProxy.inst.taskConfig;

        this.showCustomAd();
        // 误点原生广告开启时，刷新频率,开启误点原生广告不做删除，只做隐藏，同时把开始按钮移动到下方
        let adCustom = Guyu.AdFactory.getCustomAd({
            adUnitId: config.banner_adunits
        });

        this.scheduleOnce(() => {
            adCustom.hide();
        }, config.wudian_ys_showTime);

        this.scheduleOnce(() => {
            this.wudianCircleYs()
        }, config.wudian_ys_showTime + config.wudian_ys_hideTime);

    }

    solveReward() {
        let config = TaskProxy.inst.taskConfig;

        this.scheduleOnce(() => {
            const rand1 = math.random();

            // 把今天的时间做一个缓存，根据配置每天强弹的广告次数，判断当前广告是否强制弹出
            let today = Guyu.DayLite.now().format("YYYY-MM-DD");
            let todayCount = Guyu.storage.get(`todayCount${today}`);
            if (!todayCount || Number(todayCount) < config.force_click_day_count) {
                // 说明当前需要进入以后强制播放激励广告
                if (config.is_force_show_reward) {
                    if (rand1 <= config.is_force_show_reward_percent) {
                        this.showForceRewardAd()
                    }
                }
                if (config.roi_is_force_show_reward) {
                    if (rand1 <= config.roi_is_force_show_reward_percent) {
                        this.showForceRewardAd()
                    }
                }
            }
        }, config.force_click_mode2_delay)
    }

    async showForceRewardAd() {

        let config = TaskProxy.inst.taskConfig;

        let adUnitId = TaskProxy.inst.taskConfig.m_CommmonRewardID;
        if (!adUnitId) {
            console.error('未获取到广告id');
            return;
        }
        let ad = Guyu.AdFactory.getAD({ adUnitId: adUnitId, init: true });
        wx.showLoading({
            title: config.force_click_text,
        });
        this.scheduleOnce(() => {
            wx.hideLoading();
        }, 1)
        let { success, errMsg } = await ad.playAd({
            showError: true,
            showLoading: false,
        });

        let today = Guyu.DayLite.now().format("YYYY-MM-DD");
        let todayCount = Guyu.storage.get(`todayCount${today}`);
        Guyu.storage.set(`todayCount${today}`, String(Number(todayCount += 1)))
        if (!success) {
            CommonUI.showToast(errMsg);
            return;
        }
    }

    showOtherAd() {
        let config = TaskProxy.inst.taskConfig;

        // 加载原生banner广告
        this.showCustomAd()

        // 如果需要不停刷新原生广告
        if (config.ysad_fresh_time > 0) {
            this.freshYsAd()
        }

        // 展示格子广告
        if (config.is_show_gezi) {
            this.showGeziAd()
        }
    }

    showRoiOtherAd() {
        let config = TaskProxy.inst.taskConfig;

        // 加载原生banner广告
        this.showCustomAd()

        // 如果需要不停刷新原生广告
        if (config.roi_ysad_fresh_time > 0) {
            this.freshYsAd()
        }

        // 展示格子广告
        if (config.is_show_gezi) {
            this.showGeziAd()
        }
    }

    freshYsAd() {
        let config = TaskProxy.inst.taskConfig;
        this.scheduleOnce(() => {
            let adCustom = Guyu.AdFactory.getCustomAd({
                adUnitId: config.banner_adunits
            });
            adCustom.destroy();
            Guyu.AdFactory.customAdMap.delete(config.banner_adunits)
            // 时间到了销毁广告,0.5秒以后重新加载下一个原生广告
            this.scheduleOnce(() => {
                this.showCustomAd()
                this.freshYsAd()
            }, 1);
        }, config.ysad_fresh_time);
    }

    showGeziAd() {
        let config = TaskProxy.inst.taskConfig;
        let gezi_ad = Guyu.AdFactory.getCustomAd({
            adUnitId: config.gezi_adunits
        });
        let windowInfo = Guyu.AdapterManager.adapter.windowInfo;

        gezi_ad.show({
            left: 40,
            top: 100,
            width: windowInfo.screenWidth - 60
        });
    }

    showInsetAd(isRepet: boolean) {
        let config = TaskProxy.inst.taskConfig;
        let ad插屏 = Guyu.AdFactory.getInterstitialAd({ adUnitId: config.inset_adunits });

        ad插屏.show(() => {
            // 监听插屏关闭的时候是否重复15秒显示插屏
            if (isRepet) {
                this.scheduleOnce(() => {
                    this.showInsetAd(true)
                }, 15);
            }
        });
    }

    showCustomAd() {
        let config = TaskProxy.inst.taskConfig;
        let adCustom = Guyu.AdFactory.getCustomAd({
            adUnitId: config.banner_adunits
        });
        let windowInfo = Guyu.AdapterManager.adapter.windowInfo;
        let top = windowInfo.screenHeight - 110;

        if(this.wudianMode == 1 || this.wudianMode ==2){
            top = top-50
        }

        adCustom.show({
            left: 45,
            top: top,
            width: windowInfo.screenWidth - 90
        });

    }

    private showAD() {
        if (!Guyu.RuntimeSDK.onMiniGame) {
            return;
        }
        let config = TaskProxy.inst.taskConfig;
        let ad插屏 = Guyu.AdFactory.getInterstitialAd({ adUnitId: TaskProxy.inst.taskConfig.inset_adunits });
        ad插屏.show();
        let adCustom = Guyu.AdFactory.getCustomAd({
            adUnitId: config.banner_adunits
        });
        let windowInfo = Guyu.AdapterManager.adapter.windowInfo;
        let top = windowInfo.screenHeight - 128;

        adCustom.show({
            left: 0,
            top: top,
        });
    }

    private hideAD() {
        if (!Guyu.RuntimeSDK.onMiniGame) {
            return;
        }
        let config = TaskProxy.inst.taskConfig;
        // let adCustom = Guyu.AdFactory.getCustomAd({
        //     adUnitId: config.banner_adunits
        // });
        // adCustom.hide();
        // let ad插屏 = Guyu.AdFactory.getInterstitialAd({ adUnitId: TaskProxy.inst.taskConfig.inset_adunits });
        // ad插屏.hide();
    }


    ceshi() {
        localStorage.clear(); director.loadScene('jinruchangjing')
    }


    ceshi2() {
        log(SJTS.t体验机会)
    }


    ceshi3() {
        log(this.node.parent.children)
        log(this.node.parent.getChildByName('changzhuzhixin').getComponent(CZdingshiqiTS))
    }

    protected onLoad(): void {
        this.ty = find('通用管理').getComponent(tongyongTS);
        let config = TaskProxy.inst.taskConfig;
        let adUnitId1 = config.inset_adunits;
        let adUnitId2 = config.banner_adunits;
        if (Guyu.RuntimeSDK.onMiniGame) {
            Guyu.AdFactory.getInterstitialAd({ adUnitId: adUnitId1 });
            Guyu.AdFactory.getCustomAd({ adUnitId: adUnitId2 });
        }
    }

    start() {
        Guyu.dispatcher.on("gold_change", this, this.changeGold)
        if (SJTS.q其他广告开启) {
            let a = localStorage.getItem('HC_xinwanjia')
            if (a == null || a == '') {
                localStorage.setItem('HC_xinwanjia', '1');  //记录缓存
                console.log('当前为新玩家')

                SJTS.q其他广告开启 = false
                let f = () => {
                    SJTS.q其他广告开启 = true
                    console.log('指点时间到，开启其他广告')
                }

                this.ty.c常驻定时器(SJTS.d定时开启其他广告时间, f)
            }
        }

        this.缓存变量更新()
        this.数据显示变化()

        this.判断是否当日执行()
        //背景动画
        this.d背景动画()
        this.y预加载场景()



    }

    d背景动画() {
        let n = find('Canvas/背景/ma1')
        let t = tween(n).by(0.5, { angle: 8 }).by(0.5, { angle: -8 })
        tween(n).repeatForever(t).start()
        n = find('Canvas/背景/ma2')
        t = tween(n).by(0.5, { angle: -8 }).by(0.5, { angle: 8 })
        tween(n).repeatForever(t).start()
        n = find('Canvas/背景/ma3')
        t = tween(n).by(0.5, { angle: 8 }).by(0.5, { angle: -8 })
        tween(n).repeatForever(t).start()
        n = find('Canvas/背景/ma4')
        t = tween(n).by(0.5, { angle: -8 }).by(0.5, { angle: 8 })
        tween(n).repeatForever(t).start()

        n = find('Canvas/背景/yueliang')
        t = tween(n).set({ position: v3(465, 410) }).to(30, { position: v3(-465, 410) })
        tween(n).repeatForever(t).start()

        n = this.ty.find查找('Canvas/按钮2组/麻将解压/duihuakuanQ')
        this.ty.c持续旋转(n, 8, 0.8)
        n = this.ty.find查找('Canvas/按钮2组/麻将消个球/duihuakuanQ')
        this.ty.c持续旋转(n, 8, 0.8)
        n = this.ty.find查找('Canvas/按钮2组/麻了个麻/duihuakuanQ')
        this.ty.c持续旋转(n, -8, 0.8)
    }


    y预加载场景() {
        this.ty.y预加载场景('malegema')
    }

    缓存变量更新() {
        //this. = JSON.parse(localStorage.getItem(''))    
        this.HC_qiandao_riqi = JSON.parse(localStorage.getItem('HC_qiandao_riqi'))
        this.HC_wuxian_riqi = JSON.parse(localStorage.getItem('HC_wuxian_riqi'))

        this.HC_XLMJ_zuigaofen = JSON.parse(localStorage.getItem('HC_XLMJ_zuigaofen'))
        this.HC_ZGguang = JSON.parse(localStorage.getItem('HC_ZGguang'))
        this.HC_qian = JSON.parse(localStorage.getItem('HC_qian')) || 0;
        this.HC_doudongshu = JSON.parse(localStorage.getItem('HC_doudongshu'))
        this.HC_tilizhi = JSON.parse(localStorage.getItem('HC_tilizhi'))
        this.HC_wuxiantili = JSON.parse(localStorage.getItem('HC_wuxiantili'))
        this.HC_JS_MLGM = JSON.parse(localStorage.getItem('HC_JS_MLGM'))
        this.HC_JS_MJXGQ = JSON.parse(localStorage.getItem('HC_JS_MJXGQ'))
        this.HC_JS_JYMJ = JSON.parse(localStorage.getItem('HC_JS_JYMJ'))
        this.HC_JS_XLMJ = JSON.parse(localStorage.getItem('HC_JS_XLMJ'))
        this.HC_MLGM_chuangguangshu = JSON.parse(localStorage.getItem('HC_MLGM_chuangguangshu'))

    }

    changeGold(gold: number) {

        this.HC_qian = gold;
        this.数据显示变化()
    }

    数据显示变化() {
        let wzn = this.ty.find查找('Canvas/数据组/金币体力显示/金币数值文字')
        let wz = this.HC_qian + ''
        this.ty.x修改文字(wzn, wz)

        wzn = this.ty.find查找('Canvas/数据组/金币体力显示/体力数值文字')
        wz = this.HC_tilizhi + ''
        if (this.HC_wuxiantili) {
            wz = '∞'
        }
        this.ty.x修改文字(wzn, wz)
        wzn = this.ty.find查找('Canvas/弹出组/体力补充弹出/小组/kuanhuawen2/标题')
        this.ty.x修改文字(wzn, wz)

        wzn = this.ty.find查找('Canvas/弹出组/选择模式弹出/小组/按钮_积分模式/长圆/文字')
        wz = '最高得分：' + this.HC_XLMJ_zuigaofen
        this.ty.x修改文字(wzn, wz)

        wzn = this.ty.find查找('Canvas/弹出组/选择模式弹出/小组/按钮_竞速模式/长圆/文字')
        wz = '最高纪录：' + this.HC_ZGguang + '关'
        this.ty.x修改文字(wzn, wz)

        wzn = this.ty.find查找('Canvas/按钮组/按钮_开始游戏/长圆/文字')
        wz = '闯关数：' + this.HC_MLGM_chuangguangshu + '关'
        this.ty.x修改文字(wzn, wz)

        wzn = this.ty.find查找('Canvas/弹出组/体力补充弹出/小组/园按钮3/标题-001')
        wz = '(' + SJTS.w无体力观看次数 + '/3'
        this.ty.x修改文字(wzn, wz)


        let DA: Date = new Date
        let n = this.ty.find查找('Canvas/动画组/分享提示')
        if (this.HC_qiandao_riqi != DA.getDate()) {
            n.setPosition(-218, 105)
        } else {
            n.setPosition(5000, 105)
        }
    }

    判断是否当日执行() {
        let DA: Date = new Date
        if (this.HC_wuxian_riqi != DA.getDate()) {
            this.HC_wuxian_riqi = DA.getDate()
            localStorage.setItem('HC_wuxian_riqi', JSON.stringify(this.HC_wuxian_riqi));
            if (this.HC_wuxiantili) {
                this.HC_wuxiantili = false
                localStorage.setItem('HC_wuxiantili', JSON.stringify(this.HC_wuxiantili));
            }
            if (this.HC_tilizhi < 5) {
                this.HC_tilizhi = 5
                localStorage.setItem('HC_tilizhi', JSON.stringify(this.HC_tilizhi));
            }
            this.数据显示变化()
        }
    }

    onClickTask() {
        TaskView.showWnd();
    }

    AN_分享() {
        this.ty.bofangshenyin(1)
        let f = () => {
            let DA: Date = new Date
            if (this.HC_qiandao_riqi != DA.getDate()) {
                this.HC_tilizhi += this.f分享加道具数
                localStorage.setItem('HC_tilizhi', JSON.stringify(this.HC_tilizhi))
                this.HC_qiandao_riqi = DA.getDate()
                localStorage.setItem('HC_qiandao_riqi', JSON.stringify(this.HC_qiandao_riqi));
                this.数据显示变化()

                let n = this.ty.find查找('Canvas/动画组/分享提示')
                this.ty.find查找('Canvas/动画组/分享提示').getComponent(UIOpacity).opacity = 0
                Tween.stopAllByTarget(n)
            }
        }

        this.ty.f分享(f)

    }


    AN_游戏大全() {
        weixinapi.t跳转小程序()
    }



    AN_设置打开() {
        this.ty.bofangshenyin(1)
        let n = this.ty.find查找('Canvas/弹出组/设置弹出')
        n.setPosition(-1000, 0)
        tween(n).to(0.3, { position: v3(0, 0) }).start()
    }

    AN_设置关闭() {
        this.ty.bofangshenyin(1)
        let n = this.ty.find查找('Canvas/弹出组/设置弹出')
        tween(n).to(0.3, { position: v3(-1000, 0) }).start()
    }

    AN_排行榜打开() {
        this.ty.c创建插屏()
        this.ty.bofangshenyin(1)
        let n = this.ty.find查找('Canvas/弹出组/弹出_排行版')
        n.setPosition(-1000, 0)
        tween(n).to(0.3, { position: v3(0, 0) }).start()
    }

    AN_排行榜关闭() {
        this.ty.bofangshenyin(1)
        let n = this.ty.find查找('Canvas/弹出组/弹出_排行版')
        tween(n).to(0.3, { position: v3(-1000, 0) }).start()
    }

    k可点击 = true
    积分模式(e: EventTouch) {
        if (this.k可点击) {
            if (this.HC_tilizhi > 0 || this.HC_wuxiantili) {
                this.ty.bofangshenyin(2)
                SJTS.j进入模式 = 1
                this.k可点击 = false
                if (!this.HC_wuxiantili) {
                    let n = find('Canvas/动画组/体力消失')
                    let p = v3(e.target.position.x + 135, e.target.position.y + 20)
                    n.setPosition(p)
                    tween(n).by(0.6, { position: v3(0, 50, 0) })
                        .call(() => {
                            this.HC_tilizhi -= 1
                            localStorage.setItem('HC_tilizhi', JSON.stringify(this.HC_tilizhi))
                            this.数据显示变化()
                            n.setPosition(1000, 0)
                            this.j进入动画('MJ_xialuo')
                        })
                        .start()
                } else {
                    this.j进入动画('MJ_xialuo')
                }
            } else {
                this.t体力不足弹出()
            }
        }
    }

    竞速模式(e: EventTouch) {
        if (this.k可点击) {
            if (this.HC_tilizhi > 0 || this.HC_wuxiantili) {
                this.ty.bofangshenyin(2)
                SJTS.j进入模式 = 2
                this.k可点击 = false
                if (!this.HC_wuxiantili) {
                    let n = find('Canvas/动画组/体力消失')
                    let p = v3(e.target.position.x + 135, e.target.position.y + 20)
                    n.setPosition(p)
                    tween(n).by(0.6, { position: v3(0, 50, 0) })
                        .call(() => {
                            this.HC_tilizhi -= 1
                            localStorage.setItem('HC_tilizhi', JSON.stringify(this.HC_tilizhi))
                            this.数据显示变化()
                            n.setPosition(1000, 0)

                            this.j进入动画('MJ_xialuo')
                        })
                        .start()

                } else {
                    this.j进入动画('MJ_xialuo')
                }
            } else {
                this.t体力不足弹出()
            }
        }
    }


    j进入麻将解压馆模式() {
        if (this.k可点击) {
            if (this.HC_tilizhi > 0 || this.HC_wuxiantili) {
                this.ty.bofangshenyin(2)
                this.k可点击 = false
                if (!this.HC_wuxiantili) {
                    let n = find('Canvas/动画组/体力消失')
                    let ann = this.ty.find查找('Canvas/按钮2组/麻将解压')
                    let p = v3(ann.position.x + 135, ann.position.y + 20)
                    n.setPosition(p)
                    tween(n).by(0.6, { position: v3(0, 50, 0) })
                        .call(() => {
                            this.HC_tilizhi -= 1
                            localStorage.setItem('HC_tilizhi', JSON.stringify(this.HC_tilizhi))
                            this.数据显示变化()
                            n.setPosition(1000, 0)
                            this.j进入动画('jieyafangkuai')
                        })
                        .start()
                } else {
                    this.j进入动画('jieyafangkuai')
                }
            } else {
                this.t体力不足弹出()
            }
        }
    }

    j进入麻将消个球模式() {
        if (this.k可点击) {
            if (this.HC_tilizhi > 0 || this.HC_wuxiantili) {
                this.ty.bofangshenyin(2)
                this.k可点击 = false
                if (!this.HC_wuxiantili) {
                    let n = find('Canvas/动画组/体力消失')
                    let ann = this.ty.find查找('Canvas/按钮2组/麻将消个球')
                    let p = v3(ann.position.x + 135, ann.position.y + 20)
                    n.setPosition(p)
                    tween(n).by(0.6, { position: v3(0, 50, 0) })
                        .call(() => {
                            this.HC_tilizhi -= 1
                            localStorage.setItem('HC_tilizhi', JSON.stringify(this.HC_tilizhi))
                            this.数据显示变化()
                            n.setPosition(1000, 0)
                            this.j进入动画('xiaogeqiu')
                        })
                        .start()
                } else {
                    this.j进入动画('xiaogeqiu')
                }
            } else {
                this.t体力不足弹出()
            }
        }
    }


    j进入麻了个麻模式() {
        if (this.k可点击) {
            if (this.HC_tilizhi > 0 || this.HC_wuxiantili) {
                this.ty.bofangshenyin(2)
                this.k可点击 = false
                if (!this.HC_wuxiantili) {
                    let n = find('Canvas/动画组/体力消失')
                    let ann = this.ty.find查找('Canvas/按钮2组/麻了个麻')
                    let p = v3(ann.position.x - 135, ann.position.y + 20)
                    n.setPosition(p)
                    tween(n).by(0.6, { position: v3(0, 50, 0) })
                        .call(() => {
                            this.HC_tilizhi -= 1
                            localStorage.setItem('HC_tilizhi', JSON.stringify(this.HC_tilizhi))
                            this.数据显示变化()
                            n.setPosition(1000, 0)
                            this.j进入动画('malegema')
                        })
                        .start()
                } else {
                    this.j进入动画('malegema')
                }
            } else {
                this.t体力不足弹出()
            }
        }
    }

    //  1解压麻将  2麻将消个球  3麻了个嘛  
    q其他模式(e, eve) {
        let but1 = this.ty.find查找('Canvas/弹出组/提示永久解锁/小组/按钮_体验')
        let but2 = this.ty.find查找('Canvas/弹出组/提示永久解锁/小组/按钮_播放')

        if (eve == 1) {
            if (this.HC_JS_JYMJ) {
                this.j进入麻将解压馆模式()
            } else {
                let tn = find('Canvas/弹出组/提示永久解锁')
                tn.setPosition(0, 0)

                this.ty.x修改Button参数(but1, '1')
                this.ty.x修改Button参数(but2, '1')

                if (SJTS.z直接播放) {
                    this.y永解解压麻将()
                }
            }
        }

        if (eve == 2) {
            if (this.HC_JS_MJXGQ) {
                this.j进入麻将消个球模式()
            } else {
                let tn = find('Canvas/弹出组/提示永久解锁')
                tn.setPosition(0, 0)

                this.ty.x修改Button参数(but1, '2')
                this.ty.x修改Button参数(but2, '2')

                if (SJTS.z直接播放) {
                    this.y永解麻将消个球()
                }
            }
        }

        if (eve == 3) {
            if (this.HC_JS_MLGM) {
                this.t弹出下落模式选择()
            } else {
                let tn = find('Canvas/弹出组/提示永久解锁')
                tn.setPosition(0, 0)

                this.ty.x修改Button参数(but1, '3')
                this.ty.x修改Button参数(but2, '3')

                if (SJTS.z直接播放) {
                    this.y永解麻了个嘛()
                }
            }
        }
    }

    t弹出下落模式选择() {
        let n = this.ty.find查找('Canvas/弹出组/选择模式弹出')
        this.ty.t弹出通用(n)
    }

    y永解解压麻将() {
        let f = () => {
            let tn = find('Canvas/弹出组/提示永久解锁')
            this.ty.g关闭通用(tn)

            this.HC_JS_JYMJ = true
            localStorage.setItem('HC_JS_JYMJ', JSON.stringify(this.HC_JS_JYMJ))
            this.HC_tilizhi++
            this.j进入麻将解压馆模式()
        }
        this.ty.c创建激励广告(f)

    }

    y永解麻将消个球() {
        let f = () => {
            let tn = find('Canvas/弹出组/提示永久解锁')
            this.ty.g关闭通用(tn)

            this.HC_JS_MJXGQ = true
            localStorage.setItem('HC_JS_MJXGQ', JSON.stringify(this.HC_JS_MJXGQ))
            this.HC_tilizhi++
            this.j进入麻将消个球模式()
        }
        this.ty.c创建激励广告(f)

    }

    y永解麻了个嘛() {
        let f = () => {
            let tn = find('Canvas/弹出组/提示永久解锁')
            this.ty.g关闭通用(tn)

            this.HC_JS_MLGM = true
            localStorage.setItem('HC_JS_MLGM', JSON.stringify(this.HC_JS_MLGM))
            this.HC_tilizhi++
            this.t弹出下落模式选择()
        }
        this.ty.c创建激励广告(f)

    }

    y永久解锁下落麻将() {
        let f = () => {
            let tn = find('Canvas/弹出组/提示永久解锁')
            this.ty.g关闭通用(tn)

            this.HC_JS_XLMJ = true
            localStorage.setItem('HC_JS_XLMJ', JSON.stringify(this.HC_JS_XLMJ))
            this.HC_tilizhi++
            this.t弹出下落模式选择()
        }
        this.ty.c创建激励广告(f)

    }

    t体验一次(a, e) {
        log(SJTS.t体验机会)
        this.HC_tilizhi++
        if (e == '1') {
            if (SJTS.t体验机会.JYMJ == 1) {
                SJTS.t体验机会.JYMJ = 0
                this.j进入麻将解压馆模式()
            } else {
                this.t提示已体验()
            }

        }
        if (e == '2') {
            if (SJTS.t体验机会.XGQ == 1) {
                log(SJTS.t体验机会)
                SJTS.t体验机会.XGQ = 0
                this.j进入麻将消个球模式()
            } else {
                this.t提示已体验()
            }

        }
        if (e == '3') {
            if (SJTS.t体验机会.XLMS == 1) {
                SJTS.t体验机会.XLMS = 0
                this.t弹出下落模式选择()
            } else {
                this.t提示已体验()
            }

        }


    }

    t提示已体验() {
        this.ty.bofangshenyin(4)
        let n = this.ty.find查找('Canvas//文字提示')
        this.ty.t提示通用('体验次数不足')
    }

    j继续播放(a, e) {
        if (e == '1') {
            this.y永解解压麻将()
        }
        if (e == '2') {
            this.y永解麻将消个球()
        }
        if (e == '3') {
            this.y永解麻了个嘛()
        }
    }

    g关闭提示() {
        this.ty.bofangshenyin(1)
        let n = this.ty.find查找('Canvas/弹出组/提示永久解锁')
        this.ty.g关闭通用(n)
    }

    j进入动画(scename: string) {
        let n = find('Canvas/tongyongnode/加载')
        n.setPosition(800, 0)
        tween(n).to(0.4, { position: v3(0, 0, 0) }).call(() => {
            director.loadScene(scename)
        }).start()
    }

    t体力不足弹出() {
        this.ty.bofangshenyin(4)
        let n = find('Canvas/弹出组/体力补充弹出')
        this.ty.t弹出通用(n)

        n = find('Canvas/弹出组/体力补充弹出/小组/kuanhuawen2/tilixin')
        this.ty.c持续旋转(n, 8, 0.3)
    }

    AN_体力关闭() {
        this.ty.bofangshenyin(1)
        let n = find('Canvas/弹出组/体力补充弹出')
        n.setPosition(2000, 0)
    }

    AN_体力补充() {
        let f = () => {
            this.HC_tilizhi += 1
            localStorage.setItem('HC_tilizhi', JSON.stringify(this.HC_tilizhi))
            this.数据显示变化()
        }
        this.ty.c创建激励广告(f)

    }

    AN_体力金币补充() {
        if (this.HC_qian >= 200) {
            this.ty.bofangshenyin(1)
            this.HC_qian -= 200
            this.HC_tilizhi += 1
            localStorage.setItem('HC_tilizhi', JSON.stringify(this.HC_tilizhi))
            localStorage.setItem('HC_qian', JSON.stringify(this.HC_qian))
            this.数据显示变化()
        } else {
            this.ty.bofangshenyin(4)
            let n = this.ty.find查找('Canvas/数据组/金币体力显示/金币数值文字')
            this.ty.d抖动(n)
        }

    }

    AN_无限体力补充() {
        if (!this.HC_wuxiantili) {
            let f = () => {
                SJTS.w无体力观看次数++
                if (SJTS.w无体力观看次数 >= 3) {
                    this.HC_wuxiantili = true
                    localStorage.setItem('HC_wuxiantili', JSON.stringify(this.HC_wuxiantili));
                    localStorage.setItem('HC_tilizhi', JSON.stringify(this.HC_tilizhi))
                    let DA: Date = new Date
                    this.HC_qiandao_riqi = DA.getDate()
                    this.AN_体力关闭()
                }
                this.数据显示变化()
            }
            this.ty.c创建激励广告(f)

        }

    }
}
